<!-- INCLUDE sv_overall_header.html -->

<SCRIPT>
var form_submitted = false;

function validate() 
{
	if( form_submitted == true )
	{
		return false;
  	}
  	
	corp_id = document.forms['short_sell_form'].corp_id.value;
	if (corp_id == '') 
	{		
		$( "#dialog" ).html('{L_SV_PLEASE_INPUT}{L_SV_STOCK_ID}');
		$( "#dialog" ).dialog({			
			height: 70,
			modal: true			
		});
		return false;
	}
	number = document.forms['short_sell_form'].number.value;
	if (number == '') 
	{		
		$( "#dialog" ).html('{L_SV_PLEASE_INPUT}{L_SV_NUMBER}');
		$( "#dialog" ).dialog({			
			height: 70,
			modal: true			
		});
		return false;
	}
	if (is_valid_corp_id(corp_id) == false || document.forms['short_sell_form'].corp_id_check.value == 0)
	{
		$( "#dialog" ).html('{L_SV_NO_THIS_CORP_ID}');
		$( "#dialog" ).dialog({			
			height: 70,
			modal: true			
		});		
		return false;
	}
	
	market_price = document.getElementById('request_price_radio_0').checked;
	//alert(market_price);

	if (market_price)
	{
		document.forms['short_sell_form'].elements['request_price'].value = 0;				
	}
	else
	{
		request_price = parseFloat(document.forms['short_sell_form'].elements['request_price_text'].value);
				
		if (request_price > 0 && request_price < 99999)
		{
			document.forms['short_sell_form'].elements['request_price'].value = request_price;
		}
		else
		{
			alert('{L_SV_REQUEST_PRICE_NOT_OK}');
			return false;
		}
	}
	
	form_submitted = true; 
	
	return true;
}

function is_valid_corp_id(corp_id)
{
	if (corp_id.length < 4 || corp_id.length > 6)
	{
		return false;
	}
	return true;
}
</SCRIPT>
<script language="Javascript">
function Comma(number) 
{
number = '' + number;
if (number.length > 3) {
var mod = number.length % 3;
var output = (mod > 0 ? (number.substring(0,mod)) : '');
for (i=0 ; i < Math.floor(number.length / 3); i++) {
if ((mod == 0) && (i == 0))
output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
else
output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
return (output);
}
else return number;
}

function xmlhttpPost(strURL) 
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) 
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() 
	{
        if (self.xmlHttpReq.readyState == 4)
		{
			if (self.xmlHttpReq.responseText == '')
			{
				updatepage("<p>{L_SV_NO_THIS_CORP_ID}</p>");
				document.forms['short_sell_form'].corp_id_check.value = 0;
			    document.forms['short_sell_form'].refered_price.value = 0.0;
   				update_cash_needed();
			}
			else
			{
			    // get result back.
			    var response = self.xmlHttpReq.responseText;
			    var i = response.search(' ');
			    var corp_name = response.slice(0, i);
			    var price = response.slice(i);
				var str = "<p>" + corp_name + ' ({L_SV_REFERED_PRICE}:' + price + ")</p>";
				updatepage(str);
				document.forms['short_sell_form'].corp_id_check.value = 1;
				document.forms['short_sell_form'].refered_price.value = price;
				update_cash_needed();
			}
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() 
{
    var	corp_id = document.forms['short_sell_form'].corp_id.value;
	
    qstr = 'mode=corp_name&corp_id=' + escape(corp_id);  // NOTE: no '?' before querystring
    return qstr;
}

function updatepage(str){
    $( "#get_corp_name_result" ).html(str);	
}

function update_cash_needed()
{
    var price = document.forms['short_sell_form'].refered_price.value;

    if (price == 0.0)
    {
        $( "#cash_needed" ).html("");
    }
    else
    {
        var num = document.forms['short_sell_form'].number.value;
        var str = parseInt(num * 1000 * price * 0.9);
        str 	= '{L_SV_DEPOSIT_REQUIRED}' + Comma(str);
        
        $( "#cash_needed" ).html(str);
    }
}

function get_corp_name()
{
	<!-- IF IN_FB_IFRAME -->
	xmlhttpPost('../query.php');
	<!-- ELSE -->
	xmlhttpPost('query.php');
	<!-- ENDIF -->	
}

function set_corp_id(corp_id)
{
	document.forms['short_sell_form'].corp_id.value = corp_id;
}

$(document).ready(function()
{
	if (document.forms['short_sell_form'].corp_id.value != '')
    {
        get_corp_name();
    }
    
    <!-- IF IN_FB_IFRAME -->
    $("#corp_id").autocomplete( { source: "../query.php?mode=all_corp_id_name" });
    <!-- ELSE -->
	$("#corp_id").autocomplete( { source: "query.php?mode=all_corp_id_name" });
	<!-- ENDIF -->	    
    
    $("#corp_id").autocomplete( { close: function(event, ui)
    	{
	    	//alert('aaa');
	    	get_corp_name();
    	}    
    });
    
  	$("#corp_id").focus();
});


function ShowContent(d) 
{
	document.getElementById(d).style.display = "block";
}

function HideContent(d) 
{
	document.getElementById(d).style.display = "none";
}
	
function ShowRequestPriceDiv()
{
	ShowContent('request_price_div');
	HideContent('market_price_div');
	document.getElementById("request_price_radio_1").checked = true;
	document.getElementById("request_price_text").focus();
}
    
function onPriceTextChange()
{
	document.getElementById("request_price_radio_1").checked = true;
}

</script>

<!-- IF not S_USER_LOGGED_IN and not S_IS_BOT -->
	<form method="post" action="{S_LOGIN_ACTION}" class="headerspace" >
	<h3><a href="{U_LOGIN_LOGOUT}">{L_LOGIN_LOGOUT}</a><!-- IF S_REGISTER_ENABLED -->&nbsp; &bull; &nbsp;<a href="{U_REGISTER}">{L_REGISTER}</a><!-- ENDIF --></h3>
		<fieldset class="quick-login">
			<label for="username">{L_USERNAME}:</label>&nbsp;<input type="text" name="username" id="username" size="10" class="inputbox" title="{L_USERNAME}" />
			<label for="password">{L_PASSWORD}:</label>&nbsp;<input type="password" name="password" id="password" size="10" class="inputbox" title="{L_PASSWORD}" />
			<!-- IF S_AUTOLOGIN_ENABLED -->
				| <label for="autologin">{L_LOG_ME_IN} <input type="checkbox" name="autologin" id="autologin" /></label>
			<!-- ENDIF -->
			<input type="submit" name="login" value="{L_LOGIN}" class="button2" />
			{S_LOGIN_REDIRECT}
		</fieldset>
	</form>
<!-- ENDIF -->


<div class="panel" style="float:left;width:40%;"> 
	<div class="inner"><span class="corners-top"><span></span></span> 
	
	<h2>{L_SV_SHORT_SELL}  &nbsp<img title="{L_SV_SHORT_SELL_PAGE_INFO}" src="{T_IMAGES_PATH}icons/smile/info.gif" alt="info" /></h2> 
	
	</div>
	<table >
	<form name="short_sell_form" method="post" action="{S_SHORT_SELL_ACTION}" onsubmit="return validate();" >
		
		<fieldset class="quick-login">
		<tr title="{L_SV_COMMON_TIP_CORP_ID}">
			<td style="width:7em;">
			<p>
				<label for="corp_id">{L_SV_STOCK_ID}:</label>&nbsp;
			</p></td>
			<td style="width:20em;">
				<input type="text" name="corp_id" id="corp_id" style="width:6em;" class="inputbox" title="{L_SV_STOCK_ID}" onchange="get_corp_name()" value="{PREVIOUS_CORP_ID}"/>  
			
		
			<div id="get_corp_name_result"></div>
			<a href="http://mops.twse.com.tw/mops/web/t05st03" target="_blank"><p>{L_SV_QUERY_STOCK_ID}</p></a><BR>
			</p></td>
		</tr>
		<tr title="{L_SV_SHORT_SELL_PAGE_TIP_NUMBER}">
			<td><p>
			<label for="number">{L_SV_NUMBER}:</label>&nbsp;				
			</p></td>
			<td><p>
				<select name="number" id="number" class="row2" title="{L_SV_NUMBER}" value="{PREVIOUS_NUMBER}" style="width:5em" onchange="update_cash_needed()">
					<!-- IF PREVIOUS_NUMBER == 1 --> <OPTION VALUE="1" SELECTED>1 </OPTION><!-- ELSE --> <OPTION VALUE="1">1 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 2 --> <OPTION VALUE="2" SELECTED>2 </OPTION><!-- ELSE --> <OPTION VALUE="2">2 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 3 --> <OPTION VALUE="3" SELECTED>3 </OPTION><!-- ELSE --> <OPTION VALUE="3">3 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 4 --> <OPTION VALUE="4" SELECTED>4 </OPTION><!-- ELSE --> <OPTION VALUE="4">4 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 5 --> <OPTION VALUE="5" SELECTED>5 </OPTION><!-- ELSE --> <OPTION VALUE="5">5 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 10 --> <OPTION VALUE="10" SELECTED>10 </OPTION><!-- ELSE --> <OPTION VALUE="10">10 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 20 --> <OPTION VALUE="20" SELECTED>20 </OPTION><!-- ELSE --> <OPTION VALUE="20">20 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 50 --> <OPTION VALUE="50" SELECTED>50 </OPTION><!-- ELSE --> <OPTION VALUE="50">50 </OPTION><!-- ENDIF -->
					<!-- IF PREVIOUS_NUMBER == 100 --> <OPTION VALUE="100" SELECTED>100 </OPTION><!-- ELSE --> <OPTION VALUE="100">100 </OPTION><!-- ENDIF -->
				</select>
				<div id="cash_needed"></div>

			</p></td>
		</tr>
	</table>
	
	
	<input type="hidden" name="request_price" id="request_price" value="0">
	
	<div id="market_price_div" style="display:block;">
	<table width="40%">			
		<tr title="{L_SV_REQUEST_PRICE_TIP_NOTE}"> 
			<td ><label ><p>{L_SV_REQUEST_PRICE}:</p></label> </td> 
			<td ><label > <p> {L_SV_MARKET_PRICE}  <a href="javascript:ShowRequestPriceDiv();">
					({L_SV_SPECIFY_PRICE_LINK})
				</a> </p>
			</td> 			
		</tr>		
	</table>    			
	</div>		
	    
	<div id="request_price_div" style="display:none;">
	<table>			
		<tr title="{L_SV_REQUEST_PRICE_TIP_NOTE}"> 
			<td ><label ><p>{L_SV_REQUEST_PRICE}:  </p></label> </td> 
			<td >  <input type="radio" name="request_price_radio" id="request_price_radio_0" value="0" checked> {L_SV_MARKET_PRICE}  </td>
			
		</tr>
		<tr title="{L_SV_REQUEST_PRICE_TIP_NOTE}"> 
			<td >  </td> 
			<td >  <input type="radio" name="request_price_radio" id="request_price_radio_1" value="1" > {L_SV_SPECIFY_PRICE}: 
			<input type="text" name="request_price_text" id="request_price_text" class="inputbox" title="{L_SV_REQUEST_PRICE_TIP_NOTE}" onchange="onPriceTextChange();" />
			 </td>	    
		</tr>
	</table>
	</div>
	
	<table >		
		<tr title="{L_SV_SHORT_SELL_PAGE_TIP_NOTE}">
			<td><p>
			<label for="note">{L_SV_NOTE}:</label>&nbsp;
			</p></td>
			<td style="width:16em;"><p>
			<input type="textarea" name="note" id="note" style="width:16em;" class="inputbox" title="{L_SV_NOTE}" /><BR>
			</p></td>
		</tr>
		<tr>
			<td/>
			<td><p>
			<input type="hidden" name="refered_price" value="0.0" />
			<input type="hidden" name="corp_id_check" value="0" />
			<input type="submit" name="login" value="{L_SV_SEND}" class="button2" />
			</p></td>
		</tr>
		</fieldset>
	</form>
	</table>
</div>


<div class="panel" style="float:right;margin-left:1em;width:52%;"> 
	<div class="inner"><span class="corners-top"><span></span></span> 
	<h2>{L_SV_HOT_CORP}</h2> <p>({L_SV_CLICK_TO_ENTER_CORP_ID})</p>
	</div>
	
	<!-- IF IN_FB_IFRAME -->
	
	<table>
	<!-- BEGIN hot_corp_list -->		
		<!-- IF hot_corp_list.INDEX % 3 == 0 -->
		<tr>
		<!-- ENDIF -->
			<td>
			
				<!-- IF hot_corp_list.INDEX < 6 -->
				<span style="font-size:large;">
				<!-- ELSEIF hot_corp_list.INDEX < 15 -->
				<span style="font-size:medium;">
				<!-- ELSEIF hot_corp_list.INDEX < 24 -->
				<span style="font-size:small;">				
				<!-- ELSE -->
				<span style="font-size:x-small;">
				<!-- ENDIF -->
				<a href="#" onclick="set_corp_id('{hot_corp_list.CORP_ID}'); get_corp_name();">{hot_corp_list.CORP_NAME}({hot_corp_list.CORP_ID})&nbsp;	</a>&nbsp;&nbsp;
				</span>
			</td>
		<!-- IF hot_corp_list.INDEX % 3 == 2 -->
		</tr>
		<!-- ENDIF -->
	<!-- END hot_corp_list -->
	</table>
	
	<!-- ELSE -->
	<table>
	<!-- BEGIN hot_corp_list -->		
		<!-- IF hot_corp_list.INDEX % 4 == 0 -->
		<tr>
		<!-- ENDIF -->
			<td>
			
				<!-- IF hot_corp_list.INDEX < 8 -->
				<span style="font-size:large;">
				<!-- ELSEIF hot_corp_list.INDEX < 20 -->
				<span style="font-size:medium;">
				<!-- ELSEIF hot_corp_list.INDEX < 32 -->
				<span style="font-size:small;">				
				<!-- ELSE -->
				<span style="font-size:x-small;">
				<!-- ENDIF -->
				<a href="#" onclick="set_corp_id('{hot_corp_list.CORP_ID}'); get_corp_name();">{hot_corp_list.CORP_NAME}({hot_corp_list.CORP_ID})&nbsp;	</a>&nbsp;&nbsp;
				</span>
			</td>
		<!-- IF hot_corp_list.INDEX % 4 == 3 -->
		</tr>
		<!-- ENDIF -->
	<!-- END hot_corp_list -->
	</table>
	<!-- ENDIF -->
	
</div>

<!-- IF S_CORPS_MAY_INTEREST -->
<div class="panel" style="float:right;margin-left:1em;width:52%;"> 
	<div class="inner"><span class="corners-top"><span></span></span> 
	<h2>{L_SV_CORPS_MAY_INTEREST}</h2> <p>({L_SV_CLICK_TO_ENTER_CORP_ID})</p>
	</div>
	
	<!-- IF IN_FB_IFRAME -->
	
	<table>
	<!-- BEGIN corps_may_interest_list -->		
		<!-- IF corps_may_interest_list.INDEX % 3 == 0 -->
		<tr>
		<!-- ENDIF -->
			<td>
			
				<!-- IF corps_may_interest_list.INDEX < 6 -->
				<span style="font-size:medium;">
				<!-- ELSEIF corps_may_interest_list.INDEX < 15 -->
				<span style="font-size:medium;">
				<!-- ELSEIF corps_may_interest_list.INDEX < 24 -->
				<span style="font-size:small;">				
				<!-- ELSE -->
				<span style="font-size:x-small;">
				<!-- ENDIF -->
				<a href="#" onclick="set_corp_id('{corps_may_interest_list.CORP_ID}'); get_corp_name();">{corps_may_interest_list.CORP_NAME}({corps_may_interest_list.CORP_ID})&nbsp;	</a>&nbsp;&nbsp;
				</span>
			</td>
		<!-- IF corps_may_interest_list.INDEX % 3 == 2 -->
		</tr>
		<!-- ENDIF -->
	<!-- END corps_may_interest_list -->
	</table>
	
	<!-- ELSE -->
	<table>
	<!-- BEGIN corps_may_interest_list -->		
		<!-- IF corps_may_interest_list.INDEX % 4 == 0 -->
		<tr>
		<!-- ENDIF -->
			<td>
			
				<!-- IF corps_may_interest_list.INDEX < 8 -->
				<span style="font-size:medium;">
				<!-- ELSEIF corps_may_interest_list.INDEX < 20 -->
				<span style="font-size:medium;">
				<!-- ELSEIF corps_may_interest_list.INDEX < 32 -->
				<span style="font-size:small;">				
				<!-- ELSE -->
				<span style="font-size:x-small;">
				<!-- ENDIF -->
				<a href="#" onclick="set_corp_id('{corps_may_interest_list.CORP_ID}'); get_corp_name();">{corps_may_interest_list.CORP_NAME}({corps_may_interest_list.CORP_ID})&nbsp;	</a>&nbsp;&nbsp;
				</span>
			</td>
		<!-- IF corps_may_interest_list.INDEX % 4 == 3 -->
		</tr>
		<!-- ENDIF -->
	<!-- END corps_may_interest_list -->
	</table>
	<!-- ENDIF -->
	
</div>
<!-- ENDIF -->

<p style="clear:both;"></p>

<!-- INCLUDE to_short_sell_delegation_list.html -->


<div id="dialog" title="{L_SV_TIPS}" style="display:none;">
</div>

<!-- INCLUDE sv_overall_footer.html -->


